import * as types from '@/stores/types'
import api from '@/api/member'

const actions = {
  [types.COMMON_LOGIN] ({ commit, state }, member) {
    return new Promise((resolve, reject) => {
      api.doLogin()
        .then((res) => {
          // 正常业务处理
        })
        .catch((res, v) => {
          console.log('actions catch', res, v)
        })
        .then((res) => {
          // set auth data
          commit(types.COMMON_LOGIN, {token: new Date().getTime()})

          resolve()
        })
    })
  },
  [types.COMMON_LOGOUT] ({ commit, state }, member) {
    console.log('actions logout', new Date().getTime())
    // clear auth data
    commit(types.COMMON_LOGOUT)
  }
}

export default actions
